package com.tmpt.controller.springmvc.handlers;

import com.tmpt.controller.springmvc.PageUtils;
import com.tmpt.dto.Result;
import com.tmpt.utils.DateTool;
import com.tmpt.utils.JsonPaginationUtils;
import com.tmpt.utils.StringUtils;
import com.tmpt.utils.WebUtils;
import com.tmptSource.dto.*;
import com.tmptSource.enums.OwUserSupportType;
import com.tmptSource.service.intf.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * Created by wxy on 2017/10/17.
 */

@Controller
@RequestMapping("/springmvc/task")
public class TaskAction {


    private Logger log = Logger.getLogger(this.getClass());

    @Resource
    private IOwIssueDeclareService owIssueDeclareService;
    @Resource
    private IOwIllegalRegisterService owIllegalRegisterService;
    @Resource
    private IOwTaskService owTaskService;
    @Resource
    private IOwJobRecordService owJobRecordService;
    @Resource
    private IOwCommiteeRecordService owCommiteeRecordService;
    @Resource
    private IOwUserTrackService owUserTrackService;
    @Resource
    private IOwWorkPlanService owWorkPlanService;
    @Resource
    private IOwExecuteRecordService owExecuteRecordService;

    @RequestMapping(value = "/addIssueDeclareWithoutLogin")
    @ResponseBody
    public Result addIssueDeclareWithoutLogin( OwIssueDeclareDto owIssueDeclareDto, HttpServletRequest request){

        Result<OwIssueDeclareDto> result = new Result();
        try {
            //插入参数
            String createman = owIssueDeclareDto.getCreateman();
            String createmanId = owIssueDeclareDto.getCreatemanId();
            owIssueDeclareDto.setCreatemanId(createmanId);
            owIssueDeclareDto.setCreateman(createman);
            owIssueDeclareDto.setCompanyId("0");
            //调用远程服务
            result =  owIssueDeclareService.addEditData(owIssueDeclareDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/addIssueDeclare")
    @ResponseBody
    public Result addIssueDeclare( OwIssueDeclareDto owIssueDeclareDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwIssueDeclareDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owIssueDeclareDto.setCreatemanId(userId);
            owIssueDeclareDto.setCreateman(username);
            owIssueDeclareDto.setCompanyId(companyId);

            //调用远程服务
            result =  owIssueDeclareService.addEditData(owIssueDeclareDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/queryIssueDeclareDealListWithoutLoginLoad")
    @ResponseBody
    public Result queryIssueDeclareDealListWithoutLoginLoad( OwIssueDeclareDto owIssueDeclareDto,PageDto pageDto,  HttpServletRequest request){

        Result<OwIssueDeclareDto> result = new Result();
        try {

            pageDto = PageUtils.resetPageDto(pageDto);

            String issueNumbers = owIssueDeclareDto.getIssueNumbers();
            String owIssueDeclareStatus1 = owIssueDeclareDto.getStatus();
            if(!StringUtils.isNull(owIssueDeclareStatus1)){
                String[] split = owIssueDeclareStatus1.split(",");
                owIssueDeclareDto.setStatusArr(split);

            }
            if(!StringUtils.isNull(issueNumbers)){
                String[] issueNumbersArr = issueNumbers.split(",");
                owIssueDeclareDto.setIssueNumberArr(issueNumbersArr);
            }

            //调用远程服务
            result =  owIssueDeclareService.queryIssueDeclareDealList(owIssueDeclareDto, pageDto);


        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
        return result;
    }


    @RequestMapping(value = "/queryIssueDeclareDealListCountWithoutLogin")
    @ResponseBody
    public Result queryIssueDeclareDealListCountWithoutLogin(String owTaskStatusStr,String findTime,String issueNumberStr, HttpServletRequest request){

        Result result = new Result();
        try {

            //调用远程服务
            result =  owIssueDeclareService.queryIssueDeclareDealCount(owTaskStatusStr,findTime,issueNumberStr);


        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
        return result;
    }

    /**
     *
     * @param owTaskDto
     * @param request
     * @return
     * 2020-05-04不登录查询任务列表接口
     */
    @RequestMapping(value = "/queryTaskListWithoutLogin")
    @ResponseBody
    public Result queryTaskListWithoutLogin( OwTaskDto owTaskDto, PageDto pageDto,HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        List<Map<String, Object>> maps = new ArrayList<>();
        try {
            pageDto = PageUtils.resetPageDto(pageDto);
            String owTaskStatus = owTaskDto.getOwTaskStatus();
            if(!StringUtils.isNull(owTaskStatus)){
                String[] split = owTaskStatus.split(",");
                owTaskDto.setOwTaskStatusArr(split);
            }
            owTaskDto.setOwTaskStatus(null);
            //调用远程服务
            result = owTaskService.queryTaskListWithoutLogin(owTaskDto, pageDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryIssueDeclareList")
    @ResponseBody
    public Result queryOffpostRecordList( OwIssueDeclareDto owIssueDeclareDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwIssueDeclareDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            String userId = WebUtils.getUserId(session);
            owIssueDeclareDto.setCreatemanId(userId);

            //调用远程服务
            result =  owIssueDeclareService.pagination(owIssueDeclareDto, null);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    @RequestMapping(value = "/addIllegalRegister")
    @ResponseBody
    public Result addIllegalRegister( OwIllegalRegisterDto owIllegalRegisterDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwIllegalRegisterDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owIllegalRegisterDto.setCreatemanId(userId);
            owIllegalRegisterDto.setCreateman(username);
            owIllegalRegisterDto.setCompanyId(companyId);

            //调用远程服务
            result =  owIllegalRegisterService.addEditData(owIllegalRegisterDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryIllegalRegisterList")
    @ResponseBody
    public Result queryIllegalRegisterList( OwIllegalRegisterDto owIllegalRegisterDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwIllegalRegisterDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            String userId = WebUtils.getUserId(session);
            owIllegalRegisterDto.setCreatemanId(userId);

            //调用远程服务
            result =  owIllegalRegisterService.pagination(owIllegalRegisterDto, null);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/addJobRecord")
    @ResponseBody
    public Result addJobRecord( OwJobRecordDto owJobRecordDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwJobRecordDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owJobRecordDto.setCreatemanId(userId);
            owJobRecordDto.setCreateman(username);
            owJobRecordDto.setCompanyId(companyId);


            //调用远程服务
            result =  owJobRecordService.addData(owJobRecordDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryJobRecordList")
    @ResponseBody
    public Result queryJobRecordList(OwJobRecordDto owJobRecordDto,String userId,PageDto pageDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwJobRecordDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            //String userId = WebUtils.getUserId(session);
            owJobRecordDto.setCreatemanId(userId);
            if(StringUtils.isNull(userId)){
                String userIdSession = WebUtils.getUserId(session);
                owJobRecordDto.setCreatemanId(userIdSession);
            }

            //分页/排序查询条件
            //默认主键desc
            pageDto = PageUtils.resetPageDto(pageDto);

            //调用远程服务
            result =  owJobRecordService.pagination(owJobRecordDto, pageDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/addCommiteeRecord")
    @ResponseBody
    public Result addCommiteeRecord( OwCommiteeRecordDto owCommiteeRecordDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwCommiteeRecordDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owCommiteeRecordDto.setCreatemanId(userId);
            owCommiteeRecordDto.setCreateman(username);
            owCommiteeRecordDto.setCompanyId(companyId);


            //调用远程服务
            result =  owCommiteeRecordService.addData(owCommiteeRecordDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryCommiteeRecordList")
    @ResponseBody
    public Result queryCommiteeRecordList(OwCommiteeRecordDto owCommiteeRecordDto,String userId,PageDto pageDto,HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwCommiteeRecordDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            owCommiteeRecordDto.setCreatemanId(userId);
            if(StringUtils.isNull(userId)){
                String userIdSession = WebUtils.getUserId(session);
                owCommiteeRecordDto.setCreatemanId(userIdSession);
            }

            //分页/排序查询条件
            //默认主键desc
            pageDto = PageUtils.resetPageDto(pageDto);


            //调用远程服务
            result =  owCommiteeRecordService.pagination(owCommiteeRecordDto, pageDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/addWorkPlan")
    @ResponseBody
    public Result addWorkPlan( OwWorkPlanDto owWorkPlanDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwWorkPlanDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owWorkPlanDto.setCreatemanId(userId);
            owWorkPlanDto.setCreateman(username);
            owWorkPlanDto.setCompanyId(companyId);


            //调用远程服务
            result =  owWorkPlanService.addData(owWorkPlanDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryWorkPlanList")
    @ResponseBody
    public Result queryWorkPlanList(OwWorkPlanDto owWorkPlanDto,PageDto pageDto, String isHistory, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwWorkPlanDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            owWorkPlanDto.setCreatemanId(owWorkPlanDto.getA2userId());
            if(StringUtils.isNull(owWorkPlanDto.getA2userId())){
                String userId = WebUtils.getUserId(session);
                owWorkPlanDto.setCreatemanId(userId);
            }

            log.debug("-===================");
            log.debug(pageDto.getPageSize());
            log.debug(pageDto.getPageCurrent());
            //分页/排序查询条件
            //默认主键desc
            pageDto = PageUtils.resetPageDto(pageDto);

            //
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("isHistory", isHistory);

            //调用远程服务
            result =  owWorkPlanService.pagination(owWorkPlanDto, pageDto, paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    @RequestMapping(value = "/addUserTrack")
    @ResponseBody
    public Result addUserTrack( OwUserTrackDto owUserTrackDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwUserTrackDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owUserTrackDto.setCreatemanId(userId);
            owUserTrackDto.setCreateman(username);
            owUserTrackDto.setCompanyId(companyId);
            //
            owUserTrackDto.setA2userId(userId);

            //调用远程服务
            result =  owUserTrackService.addData(owUserTrackDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    @RequestMapping(value = "/queryUserTrackList")
    @ResponseBody
    public Result queryUserTrackList(OwUserTrackDto owUserTrackDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwUserTrackDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            String userId = WebUtils.getUserId(session);
            owUserTrackDto.setCreatemanId(userId);
            owUserTrackDto.setCreatedate_Start(DateTool.getCurrentDateStr()+" 00:00:00");
            //调用远程服务
            result =  owUserTrackService.pagination(owUserTrackDto, null);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }




    @RequestMapping(value = "/addTask")
    @ResponseBody
    public Result addTask( OwTaskDto owTaskDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);
            owTaskDto.setCreatemanId(userId);
            owTaskDto.setCreateman(username);
            owTaskDto.setCompanyId(companyId);


            //调用远程服务
            result =  owTaskService.addData(owTaskDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    @RequestMapping(value = "/queryTaskList")
    @ResponseBody
    public Result queryTaskList( OwTaskDto owTaskDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            String userId = WebUtils.getUserId(session);
            //owTaskDto.setCreatemanId(userId);
            owTaskDto.setAssistManId(userId);

            //调用远程服务
            result =  owTaskService.pagination(owTaskDto, null);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }




    @RequestMapping(value = "/assignTask")
    @ResponseBody
    public Result assignTaskWF( String taskId, String userIdArr,  HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            List<Map<String,Object>> userList = new ArrayList<Map<String, Object>>();
            List<String> userIdList = Arrays.asList(userIdArr.split(","));
            for(String assUserId: userIdList){
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("userId",assUserId);
                map.put("owUserSupportType", OwUserSupportType.Main.getKeyName());//?????由页面指定，测试先这样
                userList.add(map);
            }

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);
            paramMap.put("username", username);
            paramMap.put("companyId", companyId);
            paramMap.put("owTaskId", taskId);
            paramMap.put("userList", userList);

            //调用远程服务
            result = owTaskService.assignTaskWF(paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    @RequestMapping(value = "/queryMyTaskListWF")
    @ResponseBody
    public Result queryMyTaskListWF(HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId",userId);

            //调用远程服务
            result = owTaskService.queryMyTaskWF(paramMap);

            String pageJson = resultObj2PageJson(result);
            JsonPaginationUtils.responseWriter(response, pageJson);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/queryMyTaskListWF4App")
    @ResponseBody
    public Result queryMyTaskListWF4App(OwTaskDto owTaskDto, HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);
            paramMap.put("owTaskType", owTaskDto.getOwTaskType());


            //调用远程服务
            result = owTaskService.queryMyTaskWF(paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/claimTaskWF")
    @ResponseBody
    public Result claimTaskWF(OwTaskDto owTaskDto,HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);

            //调用远程服务
            result = owTaskService.claimTaskWF(owTaskDto, paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/dealMyTaskWF")
    @ResponseBody
    public Result dealMyTaskWF(OwTaskDto owTaskDto,HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId",userId);
            //调用远程服务
            result = owTaskService.dealMyTaskWF(owTaskDto, paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    @RequestMapping(value = "/queryMyFinishedTaskListWF")
    @ResponseBody
    public Result queryMyFinishedTaskListWF(OwTaskDto owTaskDto,PageDto pageDto, HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskAnswerDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);

            //分页/排序查询条件
            //默认主键desc
            pageDto = PageUtils.resetPageDto(pageDto);

            //调用远程服务
            result = owTaskService.queryCompletedMyTaskWF(paramMap,owTaskDto,pageDto);

            String pageJson = resultObj2PageJson(result);

            JsonPaginationUtils.responseWriter(response, pageJson);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/queryMyFinishedTaskListWF4App")
    @ResponseBody
    public Result queryMyFinishedTaskListWF4App(OwTaskDto owTaskDto, String userId, PageDto pageDto, HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskAnswerDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userIdSession = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            log.debug("==========>userId:"+userId);
            log.debug("==========>userIdSession:"+userIdSession);
            Map<String,Object> paramMap = new HashMap<String, Object>();
            if(StringUtils.isNull(userId)){
                paramMap.put("userId", userIdSession);
            }else{
                paramMap.put("userId", userId);
            }

            //分页/排序查询条件
            //默认主键desc
            //activiti中面向对象的方法来控制 id desc
            String sortColumn = pageDto.getSortColumn();
            String sortOrder = pageDto.getSortOrder();
            int page = pageDto.getPageCurrent();
            int rows = pageDto.getPageSize();
            pageDto.setPageCurrent(page - 1);
            pageDto.setPageSize(rows);

            //调用远程服务
            result = owTaskService.queryCompletedMyTaskWF(paramMap, owTaskDto, pageDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/queryMyApplyTaskListWF")
    @ResponseBody
    public Result queryMyApplyTaskListWF(HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);

            //调用远程服务
            result = owTaskService.queryMyApplyTaskWF(paramMap);

            String pageJson = resultObj2PageJson(result);

            JsonPaginationUtils.responseWriter(response, pageJson);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/queryMyApplyTaskListWF4App")
    @ResponseBody
    public Result queryMyApplyTaskListWF4App(HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("userId", userId);

            //调用远程服务
            result = owTaskService.queryMyApplyTaskWF(paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }

    @RequestMapping(value = "/completeMyTaskWF")
    @ResponseBody
    public Result completeMyTaskWF(String wfTaskId, HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("taskId",wfTaskId);

            //调用远程服务
            result = owTaskService.completeMyTaskWF(paramMap);

            String pageJson = resultObj2PageJson(result);

            JsonPaginationUtils.responseWriter(response, pageJson);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }



    public String resultObj2PageJson( Result resultObj ){
        if(!resultObj.isSuccess()){
            /*this.result = "error:"+resultObj.getContent();
            JsonPaginationUtils.responseWriter(response, this.result);
            return "jsonResult";*/
        }
        Map<String,Object> resultMap = resultObj.getResultMap();

        //分页记录
        List<OwTaskDto> list = (List<OwTaskDto>)resultMap.get("rows");
        JSONArray jsonArrayRows = JSONArray.fromObject(list);

        //分页总记录数
        int total = 0;
        if(resultMap.get("total") != null){
            total = Integer.parseInt(resultMap.get("total").toString());
        }

        //分页合计（select '合计' as c1, sum(balance) as c2 ....）
        JSONArray jsonArrayFooter = null;
        if(resultMap.get("footer")!=null){
            jsonArrayFooter = JSONArray.fromObject(resultMap.get("footer"));
        }

        JSONObject json = new JSONObject();
        json.put("total", total);
        json.put("rows", jsonArrayRows);
        //json.put("reportSqlString",reportSqlString);
        if(jsonArrayFooter!=null){
            json.put("footer", jsonArrayFooter);
        }

        String result = json.toString();

        return result;
    }


    /**
     * 向任务组中加用户
     * @param wfTaskId
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/addGroupUserWF")
    @ResponseBody
    public Result addGroupUserWF(String taskId, String wfTaskId,
                                 @RequestParam(value = "mainManId[]")  String[] mainManId,
                                 @RequestParam(value = "mainManName[]")  String[] mainManName,
                                 @RequestParam(value = "assistManId[]")  String[] assistManId,
                                 @RequestParam(value = "assistManName[]")  String[] assistManName,
                                 HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        log.debug("====>addGroupUserWF：taskId:" + taskId);
        log.debug("====>addGroupUserWF：wfTaskId:" + wfTaskId);
        log.debug("====>addGroupUserWF：mainManId:"+mainManId);
        log.debug("====>addGroupUserWF：assistManId:"+assistManId);

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            List<String> mainManIdList = Arrays.asList(mainManId);
            List<String> mainManNameList = Arrays.asList(mainManName);
            List<String> assistManIdList = Arrays.asList(assistManId);
            List<String> assistManNameList = Arrays.asList(assistManName);
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("taskId",taskId);
            paramMap.put("wfTaskId",wfTaskId);
            paramMap.put("mainManIdList",mainManIdList);
            paramMap.put("mainManNameList",mainManNameList);
            paramMap.put("assistManIdList",assistManIdList);
            paramMap.put("assistManNameList",assistManNameList);
            paramMap.put("userId",userId);
            paramMap.put("username",username);
            paramMap.put("companyId",companyId);

            //调用远程服务
            result = owTaskService.addGroupUserWF(paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault(e.getLocalizedMessage());
        }finally {
        }
    }


    /**
     * 向任务组中删除用户
     * @param wfTaskId
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/removeGroupUserWF")
    @ResponseBody
    public Result removeGroupUserWF(String wfTaskId, @RequestParam(value = "userIds[]")  String[] userIds, HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();

        Result<OwTaskDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //插入参数
            String userId = WebUtils.getUserId(session);
            String username = WebUtils.getUsername(session);
            String companyId = WebUtils.getCompanyId(session);

            List<String> userIdList = Arrays.asList(userIds);
            Map<String,Object> paramMap = new HashMap<String, Object>();
            paramMap.put("taskId",wfTaskId);
            paramMap.put("userIdList",userIdList);

            //调用远程服务
            result = owTaskService.removeGroupUserWF(paramMap);

            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault("Exception:"+e.getLocalizedMessage());
        }finally {
        }
    }



    /**
     * 分页查询执勤记录
     * @return
     */
    @RequestMapping(value = "/paginationOwExecuteRecord")
    @ResponseBody
    public Result paginationOwExecuteRecord(OwExecuteRecordDto owExecuteRecordDto,String userId,PageDto pageDto, HttpServletRequest request){
        HttpSession session = request.getSession();

        Result<OwExecuteRecordDto> result = new Result();
        try {
            if(!WebUtils.isLoginSuccess(session)){
                return result.fault("请先登录");
            }
            //查询参数
            //String userId = WebUtils.getUserId(session);
            owExecuteRecordDto.setCreatemanId(userId);
            if(StringUtils.isNull(userId)){
                String userIdSession = WebUtils.getUserId(session);
                owExecuteRecordDto.setCreatemanId(userIdSession);
            }

            //分页/排序查询条件
            //默认主键desc
            pageDto = PageUtils.resetPageDto(pageDto);

            //调用远程服务
            result =  owExecuteRecordService.pagination(owExecuteRecordDto, pageDto);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.fault("Exception:"+e.getLocalizedMessage());
        }finally {
        }
    }




}
